package com.caishi.lkx.user.service.impl;

import com.alibaba.excel.EasyExcel;
import com.caishi.lkx.user.mapper.DepartmentMapper;
import com.caishi.lkx.user.model.DepartmentModel;
import com.caishi.lkx.user.service.IDepartmentService;
import com.caishi.lkx.user.service.IGroupService;
import com.caishi.lkx.user.vo.DepartmentImportVo;
import com.zzw.common.entity.IBaseMapper;
import com.caishi.lkx.user.excelListener.ImportDepartmentListener;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author by keray
 * date:2021/4/28 3:19 下午
 */
@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Resource
    private DepartmentMapper departmentMapper;

    @Resource
    private IGroupService groupService;
    @Override
    public IBaseMapper<DepartmentModel, Long> getMapper() {
        return departmentMapper;
    }

    @Override
    public DepartmentModel builder() {
        return new DepartmentModel();
    }

    @Override
    public Boolean importDepartment(MultipartFile file, Long groupId,String userId) throws IOException {
 //       GroupModel group = groupService.getById(groupId);
//        if (!group.getStatus()) {
//            //机构过期
//            throw new BizRuntimeException(UserResultCode.groupExpired);
//        }
        EasyExcel.read(file.getInputStream(), DepartmentImportVo.class,new ImportDepartmentListener(userId,departmentMapper,groupId))
                .sheet().doRead();
        return true;
    }
}
